﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.IO.IsolatedStorage;
using System.IO;
using System.Runtime.Serialization;

namespace BankProject
{
    public partial class ViewPage : PhoneApplicationPage
    {
        List<Banks> banks = new List<Banks>();
        public ViewPage()
        {
            InitializeComponent();
        }

        void BanksAdd()
        {
            //banks = new List<Banks>();

            banks.Add(new Banks { Name = "ПриватБанк" });
            banks.Add(new Banks { Name = "АльфаБанк" });
            banks.Add(new Banks { Name = "Пумб" });
            banks.Add(new Banks { Name = "Астра Банк" });
            banks.Add(new Banks { Name = "Базис" });
            banks.Add(new Banks { Name = "Мегабанк" });
            banks.Add(new Banks { Name = "Надра Банк" });
            banks.Add(new Banks { Name = "СоцКомБанк" });
            banks.Add(new Banks { Name = "Синтез" });
            banks.Add(new Banks { Name = "Трансбанк" });
            banks.Add(new Banks { Name = "Укрпромбанк" });
            banks.Add(new Banks { Name = "Укрэксимбанк" });
            banks.Add(new Banks { Name = "Укрпромбанк" });
            banks.Add(new Banks { Name = "Райффайзен Банк Аваль" });
            banks.Add(new Banks { Name = "Укргазбанк" });


            SaveToFile("banks.xml", banks);
        }

        public static void SaveToFile(string path, object objForSave)
        {
            using (IsolatedStorageFileStream file = new IsolatedStorageFileStream(path, FileMode.OpenOrCreate, App.Store))
            {

                Serialize(file, objForSave);
                file.Close();
            };
        }

        private static void Serialize(Stream streamObject, object objForSerialization)
        {
            if (objForSerialization == null || streamObject == null)
                return;

            DataContractSerializer ser = new DataContractSerializer(objForSerialization.GetType());
            ser.WriteObject(streamObject, objForSerialization);
        }
    }
}
